<template>
    <!-- 添加或修改生产事件补录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="150px">
        <el-form-item label="生产事件原因" prop="detailEventReason">
          <el-input v-model="detailForm.detailEventReason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="生产事件影响" prop="detailEventEffective">
          <el-input v-model="detailForm.detailEventEffective" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="发现阶段" prop="detailEventDiscoveryStage">
          <el-select v-model="detailForm.detailEventDiscoveryStage" placeholder="请选择发现阶段">
            <el-option
              v-for="dict in dict.type.event_discovery_stage"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发现方式" prop="detailEventDiscoveryWay">
          <el-select v-model="detailForm.detailEventDiscoveryWay" placeholder="请选择发现方式">
            <el-option
              v-for="dict in dict.type.event_discovery_way"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="反馈行" prop="detailEventFeedBank">
          <el-input v-model="detailForm.detailEventFeedBank" placeholder="请输入反馈行" />
        </el-form-item>
        <el-form-item label="处理措施" prop="detailEventTreatment">
          <el-input v-model="detailForm.detailEventTreatment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="关联cq" prop="detailLinkCq">
          <el-input v-model="detailForm.detailLinkCq" placeholder="请输入关联cq" />
        </el-form-item>
        <el-form-item label="关联变更单号" prop="detailLinkChangeCode">
          <el-input v-model="detailForm.detailLinkChangeCode" placeholder="请输入关联变更单号" />
        </el-form-item>
        <el-form-item label="处理状态" prop="detailEventSloveState">
          <el-select v-model="detailForm.detailEventSloveState" placeholder="请选择处理状态">
            <el-option
              v-for="dict in dict.type.product_event_slove_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="问题单号" prop="detailPbmCode">
          <el-input v-model="detailForm.detailPbmCode" placeholder="请输入问题单号" />
        </el-form-item>
        <el-form-item label="对应发版CQ涉及部门" prop="detailAboutDept">
          <el-input v-model="detailForm.detailAboutDept" placeholder="请输入涉及部门" />
        </el-form-item>
        <el-form-item label="表象系统所属部门" prop="detailSurfaceDept">
          <el-input v-model="detailForm.detailSurfaceDept" placeholder="请输入表象系统所属部门" />
        </el-form-item>
        <el-form-item label="备注" prop="detailRemark">
          <el-input v-model="detailForm.detailRemark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
</template>

<script>

import {
  listProductEventDetail,
  getProductEventDetail,
  delProductEventDetail,
  addProductEventDetail,
  updateProductEventDetail,
  getDetailByEventId, submitEventDetail
} from "@/api/yjcz/productEventDetail";


export default {
  name: "addDetailDialog",
  dicts: ['event_discovery_stage', 'event_discovery_way', 'product_event_slove_state'],
  data() {
    return {
      open: false,
      title: '生产事件补录',
      detailForm: {},
      rules: {
        detailEventReason: [
          { required: true, message: "生产事件原因不能为空", trigger: "blur" },
          { min: 3, max: 1000, message: '长度在 3 到 1000 个字符', trigger: 'blur' }
        ],
        detailEventEffective: [
          { required: true, message: "生产事件影响不能为空", trigger: "blur" },
          { min: 3, max: 1000, message: '长度在 3 到 1000 个字符', trigger: 'blur' }
        ],
        detailEventDiscoveryStage: [
          { required: true, message: "发现阶段不能为空", trigger: "change" }
        ],
        detailEventDiscoveryWay: [
          { required: true, message: "发现方式不能为空", trigger: "change" }
        ],
        detailEventFeedBank: [
          { required: true, message: "反馈行不能为空", trigger: "blur" },
          { min: 3, max: 100, message: '长度在 3 到 100 个字符', trigger: 'blur' }
        ],
        detailEventTreatment: [
          { required: true, message: "处理措施不能为空", trigger: "blur" },
          { min: 3, max: 1000, message: '长度在 3 到 1000 个字符', trigger: 'blur' }
        ],
        detailLinkChangeCode: [
          { required: true, message: "关联变更单号不能为空", trigger: "blur" },
          { min: 3, max: 100, message: '长度在 3 到 100 个字符', trigger: 'blur' }
        ],
        detailLinkCq: [
          { min: 3, max: 100, message: '长度在 3 到 100 个字符', trigger: 'blur' }
        ],
        detailEventSloveState: [
          { required: true, message: "处理状态不能为空", trigger: "blur" },
        ],
        detailPbmCode: [
          { required: true, message: "问题单号不能为空", trigger: "blur" },
          { min: 3, max: 100, message: '长度在 3 到 100 个字符', trigger: 'blur' }
        ],
        detailAboutDept: [
          { required: true, message: "发版CQ涉及部门不能为空", trigger: "blur" },
          { min: 3, max: 200, message: '长度在 3 到 200 个字符', trigger: 'blur' }
        ],
        detailSurfaceDept: [
          { required: true, message: "表象系统所属部门不能为空", trigger: "blur" },
          { min: 3, max: 200, message: '长度在 3 到 200 个字符', trigger: 'blur' }
        ],
        detailRemark: [
          { min: 3, max: 500, message: '长度在 3 到 500 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    show (eventId) {
      this.open = true
      getDetailByEventId(eventId).then(response => {
        if (response.code === 200) {
          let form = response.data
          if (null != form && form.pkId) {
            this.detailForm = form
          } else {
            this.detailForm = {
              detailEventId: eventId
            }
          }
        } else {
          this.$modal.msgError(response.msg);
        }
      })
    },
    submitForm () {
      this.$refs["detailForm"].validate(valid => {
        if (valid) {
          submitEventDetail(this.detailForm).then(response => {
            if (response.code === 200) {
              this.$modal.msgSuccess('补录成功');
              this.$emit('refershList')
              this.open = false
            } else {
              this.$modal.msgError(response.msg);
            }
          })
        }
      })
    },
    cancel () {
      this.open = false
    }
  }
}
</script>

<style scoped>

</style>
